package com.fly.office.example;

import com.fly.office.word.model.ChartModel;
import com.fly.office.word.tool.WordTool;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.util.Map;

/**
 * 图表集合测试案例
 * @author lf
 */
public class GatherChart {

    public static void main(String[] args) {
        //图表集合模板
        String tplPath = "/word/gather.docx";
        String outPath = "D:\\data\\word\\gather.docx";

        XWPFDocument doc = WordTool.genDoc(tplPath);
        if(doc!=null)
        {
            //获取word模板中的所有图表元素
            Map<String, POIXMLDocumentPart> chartsMap = WordTool.getDocPart(doc);

            ChartModel model;
            //构建并初始化柱状图表
            model = ColumnarChart.initMultiColumnarModel();
            WordTool.initDoc(chartsMap,model);

            //构建并初始化折线图表
            model = LineChart.initModel();
            WordTool.initDoc(chartsMap,model);

            //构建并初始化饼图图表
            model = PieChart.initModel();
            WordTool.initDoc(chartsMap,model);

            //构建并初始化条形图图表
            model = BarChart.initMultiModel();
            WordTool.initDoc(chartsMap,model);

            //下载文件
            WordTool.download(doc,outPath);
        }
    }

}
